package cn.sirun.com.fca.account.observer;

import android.support.annotation.CallSuper;
import android.util.Pair;

import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.kernel.util.ExceptionUtils;
import com.tencent.cloud.iov.util.rx.SimpleObserver;

/**
 * 该Observer将请求异常转换为状态码，继续发送消息
 *
 * @author vinsonhuang
 * @date 2018/8/24
 */
public class ConvertExceptionObserver<T> extends SimpleObserver<BaseResponse<T>> {

    @CallSuper
    @Override
    public void onError(Throwable throwable) {
        super.onError(throwable);
        // 处理本地异常消息
        Pair<Integer, String> pair = ExceptionUtils.handleThrowable(throwable);
        // 本次请求向业务层发送消息
        onNext(new BaseResponse<T>(pair.first, pair.second));
    }
}
